package com.rongshu.sendmessage.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.widget.Toast;

/**
 * 判断网络情况
 * @author Administrator
 *
 */
public class NetworkState {
	/**
	 * 判断网络状态
	 * @param context
	 * @return true:有网，false:无网
	 */
	public static boolean isNetworkConnected(Context context) {
	    if (context != null) {  
	        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
	                .getSystemService(Context.CONNECTIVITY_SERVICE);
	        NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
	        if (mNetworkInfo != null) {  
	            return mNetworkInfo.isAvailable(); 
	        }  
	    }  
	    return false;  
	}

	/**
	 * 判断WIFI是否可用
	 * @param context
	 * @return true:可用； false:不可用
	 */
	public static boolean isWifiConnected(Context context) {
	    if (context != null) {  
	        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
	                .getSystemService(Context.CONNECTIVITY_SERVICE);
	        NetworkInfo mWiFiNetworkInfo = mConnectivityManager
	                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
	        if (mWiFiNetworkInfo != null) {  
	            return mWiFiNetworkInfo.isAvailable();  
	        }  
	    }  
	    return false;  
	}
	
	public void Toast(Context context, String str) {
		Toast.makeText(context, str, Toast.LENGTH_LONG).show();
	}
}
